var gulp    = require('gulp'),
uglify  = require('gulp-uglify'),          //js压缩
rename = require('gulp-rename'),           //重命名
concat  = require('gulp-concat'),          //合并文件
rev = require('gulp-rev');                 //进行hash

var outPath = './star';

gulp.task('index-js', function(){
    gulp.src(['./src/js/i18n/i18n_index.js','./src/js/main.js','./src/js/index.js'])
    .pipe(concat('index.js'))    //对js文件进行合并和重命名
    .pipe(uglify())        //对合并后的文件进行压缩
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'indexjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('help-js', function(){
    gulp.src(['./src/js/i18n/i18n_help.js','./src/js/main.js','./src/js/help.js'])
    .pipe(concat('help.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'helpjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('how-js', function(){
    gulp.src(['./src/js/i18n/i18n_how.js','./src/js/main.js','./src/js/how.js'])
    .pipe(concat('how.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'howjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('news-js', function(){
    gulp.src(['./src/js/i18n/i18n_news.js','./src/js/main.js','./src/js/news.js'])
    .pipe(concat('news.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'newsjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('star-js', function(){
    gulp.src(['./src/js/i18n/i18n_star.js','./src/js/main.js','./src/js/star.js'])
    .pipe(concat('star.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'starjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('tos-js', function(){
    gulp.src(['./src/js/i18n/i18n_tos.js','./src/js/main.js','./src/js/tos.js'])
    .pipe(concat('tos.js'))
    .pipe(uglify())
    .pipe(rev())
    .pipe(gulp.dest(outPath+'/js'))
    .pipe(rev.manifest({path:'tosjs.json', merge: true}))
    .pipe(gulp.dest('./rev'));
});

gulp.task('vue-js', function(){
    gulp.src('./src/js/lib/vue.min.js')
    .pipe(rename('5481263509794fa.js'))
    .pipe(gulp.dest(outPath+'/js'))
});

gulp.task('buildjs', ['index-js', 'help-js', 'how-js', 'news-js', 'star-js', 'tos-js', 'vue-js']);
